﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.BLL;
public partial class Supervise_TraGraph : System.Web.UI.Page
{
    public string _src = "";
    protected void Page_Load(object sender, EventArgs e)
    {

        //Graph graph = new Graph();
        //DateTime _dateEndDate = Convert.ToDateTime("2007-3-23");
        //_dateEndDate = MonthStart(_dateEndDate);
        //GraphDataSet.GraphTableDataTable GraphTable = new GraphDataSet.GraphTableDataTable();
        //GraphTable = graph.GetGraphByWhere("70", "GoodsId", 45, "1", 710000, _dateEndDate);
        //GridView1.DataSource = GraphTable.DefaultView;
        //GridView1.DataBind();

        //GraphControl1.GraphTable = GraphTable;


        try
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumHospitale);
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumSupervise);
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);
            if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
            {
                HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                if (_Account != null)
                {
                    Graph graph = new Graph();
                    DateTime _dateEndDate = Convert.ToDateTime(Request.QueryString["EndDate"]);
                    _dateEndDate = MonthStart(_dateEndDate);
                    string _strId = SysFun.ToTrim(Request.QueryString["Id"]);
                    string _strGroupField = SysFun.IsSQL(Request.QueryString["GroupField"]);
                    Int64 _intUserId = _Account.AccountId;
                    string _strUserType = _Account.Type;
                    int _intAreaid = SysFun.ToInt(_Account.AreaId);
                    int strTempAreaid = SysFun.ToInt(Request.QueryString["AreaId"]);
                    if (strTempAreaid != 0)
                    {
                        _intAreaid = strTempAreaid;
                    }

                    GraphDataSet.GraphTableDataTable GraphTable = new GraphDataSet.GraphTableDataTable();
                    ShowGoodsCompanyHospital(_strId, _strGroupField);
                    GraphTable = graph.GetGraphByWhere(_strId, _strGroupField, _intUserId, _strUserType, _intAreaid, _dateEndDate, _Account.Sort);
                    if (GraphTable != null)
                    {
                        //  GraphControl1.GraphTable = GraphTable;
                        ShowDateAndDHJE(GraphTable);
                    }
                    GraphTable.Dispose();

                }
            }
        }
        catch (Exception me)
        {
            throw me;
        }

    }
    public DateTime MonthStart(DateTime date)
    {
        DateTime dateTemp = date;
        try
        {
            int _intYear = date.Year;
            int _intMonth = date.Month;
            string _strTemp = _intYear.ToString() + "-" + _intMonth.ToString() + "-01";
            dateTemp = Convert.ToDateTime(_strTemp);
        }
        catch (Exception me)
        {
            throw me;
        }
        return dateTemp;
    }
    /// <summary>
    /// 显示每月的到货金额和定购金额
    /// </summary>
    /// <param name="GraphTable">12个月的列表</param>
    private void ShowDateAndDHJE(GraphDataSet.GraphTableDataTable GraphTable)
    {
        System.Text.StringBuilder _strbmm = new System.Text.StringBuilder();
        System.Text.StringBuilder _strbdhm = new System.Text.StringBuilder();
        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();
        strHtml.Append("<table width='98%' border='0' align='center' cellpadding='2' cellspacing='1' class='table_table'>");
        strHtml.Append("<tr>");
        strHtml.Append("<td class='table_title' nowrap>日期</td>");
        strHtml.Append("<td class='table_title' nowrap>定购金额（万元）</td>");
        strHtml.Append("<td class='table_title' nowrap>到货金额（万元）</td>");
        strHtml.Append("</tr>");
        for (int i = 0; i < 12; i++)
        {
            if (i % 2 == 0)
            {
                strHtml.Append("<tr class='table_td'>");
            }
            else
            {
                strHtml.Append("<tr class='table_td2'>");
            }
            strHtml.Append("<td >" + GraphTable[i][1].ToString() + "</td>");
            _strbmm.Append("," + GraphTable[i][1].ToString());
            strHtml.Append("<td >" + GraphTable[i][2].ToString() + "</td>");
            strHtml.Append("<td >" + GraphTable[i][3].ToString() + "</td>");
            _strbdhm.Append("," + GraphTable[i][3].ToString());
            strHtml.Append("</tr>");
        }
        strHtml.Append("</table>");
        if (_strbmm.Length > 0) _strbmm.Remove(0, 1);
        if (_strbdhm.Length > 0) _strbdhm.Remove(0, 1);
        _src = "GraphList/RepotShowImge.aspx?id1=" + SysFun.RequestEncrypt(_strbmm.ToString()) + "&id2=" + SysFun.RequestEncrypt(_strbdhm.ToString());
        labListDateAndDHJE.Text = strHtml.ToString();

    }
    private void ShowGoodsCompanyHospital(string Id, string FileType)
    {
        labInfo.Text = "";
        Graph graph = new Graph();
        switch (FileType)
        {
            case "GoodsId":
                labInfo.Text = graph.GetGoodsInfo(Id);
                break;
            case "AccountId_PS":
                labInfo.Text = graph.GetCompanyInfo(Id);
                break;
            case "AccountId_SC":
                labInfo.Text = graph.GetCompanyInfo(Id);
                break;
            case "AccountId_TB":
                labInfo.Text = graph.GetCompanyInfo(Id);
                break;
            case "AccountId_YY":
                labInfo.Text = graph.GetHospitalInfo(Id);
                break;

        }
    }
}
